package org.foxas.net
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	public class FLoaderQueue extends EventDispatcher
	{
		public var items:Array = new Array();
		public function FLoaderQueue() {
			
		}
		public function run():void{
			if(items.length==0){
				this.onComplete();
			}else{
				var _item:FLoaderQueueItem = items[0];
				_item.ob.addEventListener(Event.COMPLETE,onComplete);
				_item.funcOb();
			}
		}
		public function addnew(_NetOb:Object,_func:Function):void{
			items[items.length] = new FLoaderQueueItem(_NetOb,_func);
		}
		public function onComplete(_e:Event=null):void{
			if(items.length<=1){
				this.dispatchEvent(new Event(Event.COMPLETE));
			}else{
				items.shift();
				run();
			}
		}
	}
}
